﻿using System;
using System.Net;

class ReadFileFromInternet
{
    static void Main()
    {
        string urlAddress = "http://mbanyu.com/wp-content/uploads/2012/09/2012-Ferrari-458-Italia-Coupe-027-1680.jpg";
        string filePath = @"..\..\Ferarri-458-Italia.jpg";

        WebClient webClient = new WebClient();

        using (webClient)
        {
            try
            {
                Console.WriteLine("Downloading file, please wait...");

                webClient.DownloadFile(urlAddress, filePath);

                Console.WriteLine("The file is downloaded successfully!");
            }

            catch (ArgumentNullException)
            {
                Console.WriteLine("The URL address can not be empty!");
            }

            catch (WebException)
            {
                Console.Error.WriteLine("The address is not valid!");
            }

            catch (NotSupportedException)
            {
                Console.Error.WriteLine("This method does not support simultaneous downloads!");
            }
        }
    }
}
